<%--
  Created by IntelliJ IDEA.
  User: CMCC
  Date: 2016/8/30
  Time: 16:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/contractInfo.css"/>
    <link rel="stylesheet" href="css/pagination.css"/>
    <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript" src="js/handlebars-v3.0.3.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>
    <script type="text/javascript" src="js/security.min.js"></script>
    <script type="text/javascript" src="js/pagination.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
            var oUserInfo = document.getElementById('userInfo');
            var ocCntractInfo = document.getElementById('contractInfo');
//            var oLogInfo=document.getElementById('logInfo');
            oUserInfo.onmousedown = function () {
                ocCntractInfo.style.backgroundColor = "#fff";
                ocCntractInfo.style.color = "#000";
                oUserInfo.style.backgroundColor = "#324e75";
                oUserInfo.style.color = "#fff";
            };
            ocCntractInfo.onmousedown = function () {
                oUserInfo.style.backgroundColor = "#fff";
                oUserInfo.style.color = "#000";
                ocCntractInfo.style.backgroundColor = "#324e75";
                ocCntractInfo.style.color = "#fff";
            }
            oUserInfo.onclick = function () {
                window.location.href = hosturl+'/userInfo.jsp';
            };

//            oLogInfo.onclick=function(){
//                window.location.href='logMana.jsp';
//            };
            //添加合同信息


        }
    </script>
    <script type="text/javascript">
        var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
        console.log(hosturl);
        mui.ready(function() {
            mui.ajax(hosturl+"/contract/byUserName", {
                data: {
                    "pageNum": 0,
                    "pageSize": 10
                },
                dataType: "json",
                type: "post",
                timeout: 10000,
                success: function(data) {
                    console.log(data);
                    $('#pagination-container').pagination({
                        dataSource: data.body,
                        pageSize: 7,
                        showGoInput: true,
                        showGoButton: true,
                        autoHidePrevious: true,
                        autoHideNext: true,
                        pageNumber: 1,
                        callback: function(data, pagination) {
                            // template method of yourself
                            var html = simpleTemplating(data);
                            $('#data-container').html(html);
                        }
                    });

                },
                error: function(xhr, type, errorThrown) {
                    console.log(type);
                }
            });
        });
    </script>
    <title>合同信息</title>
</head>

<body>
<div class="top">
    <div class="top-left">
        <p class="top-left">合同管理系统</p>
    </div>
    <div class="top-right">

        <p class="p1">欢迎用户<span class=""> <%=session.getAttribute("SName")%></span>的到来 <a href="javascript:logout();"id="logout">注销 </a></p>
    </div>
</div>
<div class="left-block">
    <ul>
        <li id="contractInfo" class="cleft-index">合同管理</li>
        <li id="userInfo" class="uleft-index">用户信息</li>
        <%--<li id="logInfo" class="uleft-index">日志管理</li>--%>
    </ul>
</div>
<div class="main-part">
    <ul>
        <li class="right-label">合同信息</li>
        <!--<li class=""><input class="right-btn" type="button" value="修改合同信息" /></li>-->
        <!--<li class=""><input class="right-btn" type="button" value="搜索" /></li>-->
        <li class=""><a href="/file/download?fileName=UserOperate.docx"><input class="right-btn" type="button" id="downLoadBtn2"
                                                                                  value="下载合同模板"/></a></li>
        <li class=""><a href="/file/download?fileName=ContractTemplet.xls"><input class="right-btn" type="button" id="downLoadBtn2"
                                                                                  value="下载合同模板"/></a></li>
        <li class=""><a href="javascript:add();"><input class="right-btn" type="button" id="addBtn" value="添加合同信息"/></a></li>
        <li class=""><a href="javascript:load();"><input class="right-btn" type="button" id="loadBt" value="批量导入合同"/></a>
        </li>
            <table id="table1" class="table table-bordered table-striped table-hover">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>合同编号</th>
                    <th>合同名称</th>
                    <%--<th>用户编号</th>--%>
                    <th>付款期数</th>
                    <th>开始时间</th>
                    <th>结束时间</th>
                    <th>是否提醒</th>
                    <th>提醒时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="data-container">
                </tbody>
            </table>
            <div id="wrapper">
                <section>
                    <div id="pagination-container"></div>
                </section>
            </div>
        </li>
    </ul>
</div>
<input id="handle_status" value="" hidden="hidden">
</body>
</html>
<script type="text/javascript">
    //处理分页数据
    function simpleTemplating(data) {

        var html = '';
        $.each(data, function(index, item){
            var warnOrNor = (item.warnOrNor==false)?"否":"是";
            var remindTime = (item.remind==null)?" ":item.remind;
            html += '<tr>';
            html += '<td>'+ item.id +'</td>';
            html += '<td>'+ item.contractId +'</td>';
            html += '<td>'+ item.contractName +'</td>';
//            html += '<td>'+ item[0].userId +'</td>';
            html += '<td><a href="javascript:payRemind(' + item.id + ','+ item.times +');">' + item.times + '</a></td>';
            html += '<td>'+ item.start +'</td>';
            html += '<td>'+ item.deadline +'</td>';
            html += '<td>'+ warnOrNor +'</td>';
            html += '<td>'+ remindTime + '</td>';
            html +=  '<td><a href="javascript:update(' + item.id  + ');">修改</a></td>';
            html += '</tr>';
        });
        return html;
    };
    
    function load() {
        layer.open({
            type: 2,
            title: '批量导入合同',
            shadeClose: true,
            shade: [0.3, '#000'],
            area: ['543px', '543px'],
            content: hosturl+'/addContractByExcel.html',
            end: function () {
                var handle_status = $("#handle_status").val();
                if ( handle_status == 'OK' ) {
                    layer.msg('添加合同信息成功！',{
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    setTimeout(searchContract(),2000);
                } else if ( handle_status == 'none' ) {
                    layer.msg('添加合同信息失败！',{
                        icon: 2,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    window.location.reload();
                }
            }
        });
    };
    
    function add() {
        layer.open({
            type: 2,
            title: '添加合同信息',
            shadeClose: true,
            shade: [0.3, '#000'],
            area: ['500px', '500px'],
            content: [hosturl+'/addContract.html','no'],
            end: function () {
                var handle_status = $("#handle_status").val();
                if ( handle_status == 'OK' ) {
                    layer.msg('添加合同信息成功！',{
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    setTimeout(self.location.reload(),2000);
                } else if ( handle_status == 'none' ) {
                    layer.msg('添加合同信息失败！',{
                        icon: 2,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    window.location.reload();
                }
            }
        });
        layer.iframeAuto();
    };
    function update(id) {
        layer.open({
            type: 2,
            title: '修改合同信息',
            shadeClose: true,
            shade: [0.3, '#000'],
            area: ['500px', '500px'],
            content: [hosturl+'/updateContract.html?id='+id,'no'],
            end: function () {
                var handle_status = $("#handle_status").val();
                if ( handle_status == 'OK' ) {
                    layer.msg('修改合同信息成功！',{
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                     window.location.reload();
                } else if ( handle_status == 'none' ) {
                    layer.msg('修改合同信息失败！',{
                        icon: 2,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    });
                    window.location.reload();
                }
            }
        });
        layer.iframeAuto();
    };
    function payRemind(id, num) {
        layer.open({
            type: 2,
            title: '分期付款时间',
            shadeClose: true,
            shade: [0.3, '#000'],
            area: ['600px', '500px'],
            content: [hosturl+'/payRemind.html?id='+id+"&num="+num,'no']
        });
        layer.iframeAuto();
     };
    function logout() {
        mui.ajax(hosturl+"/user/logout", {
            data: {},
            dataType: "json",
            type: "get",
            timeout: 10000,
            success: function (datas) {
                if (datas.status == "ok") {
                    window.location.href = 'login.jsp';
                    alert(datas.description);
                }
            },
            error: function (xhr, type, errorThrown) {
                console.log(type);
            }
        });
    };
</script>


